

export default class Record {
  static _ins: Record
  static get instance() {
    return Record._ins || new Record
  }
  constructor() {
    Record._ins = this
  }

  init() {

    /** google */
    window.dataLayer = window.dataLayer || [];

    (function (d, s, id) {
      var js: HTMLScriptElement, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {
        return;
      }
      js = <HTMLScriptElement>d.createElement(s);
      js.id = id;
      js.async = true
      js.src = "https://www.googletagmanager.com/gtag/js?id=UA-91467025-37";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'google-jssdk'));

    this.gtag('js', new Date());
    this.gtag('config', 'UA-91467025-37');

    /** facebook */

    !function (f, b, e, v, n, t, s) {
      if (f.fbq) return; n = f.fbq = function () {
        n.callMethod ?
          n.callMethod.apply(n, arguments) : n.queue.push(arguments)
      };
      if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = '2.0';
      n.queue = []; t = b.createElement(e); t.async = !0;
      t.src = v; s = b.getElementsByTagName(e)[0];
      s.parentNode.insertBefore(t, s)


      var noscript = document.createElement('noscript')
      noscript.innerHTML = '<img height="1" width="1" style="display:none" src = "https://www.facebook.com/tr?id=1205955192872916&ev=PageView&noscript=1" />'
      document.body.appendChild(noscript)
    }(window, document, 'script',
      'https://connect.facebook.net/en_US/fbevents.js');
    window.fbq('init', '1205955192872916');
    window.fbq('track', 'PageView');

  }

  gtag(...args) {
    window.dataLayer.push(arguments);
  }

  /**
   * 老玩家礼包领取成功
   */
  point1() {
    this.gtag('event', 'laowanjia', {
      'event_category': 'laowanjia_category',
      'event_label': 'laowanjia_label'
    });
    window.fbq('track', 'CompleteRegistration');
  }

  // /**
  //  * 竞猜成功
  //  */
  // point2() {
  //   this.gtag('event', 'jingcai', {
  //     'event_category': 'jingcai_category',
  //     'event_label': 'jingcai_label'
  //   });
  //   window.fbq('track', 'AddToCart')
  // }

  /**
   * 第一天礼包领取成功
   */
  point3() {
    this.gtag('event', 'firstday', {
      'event_category': 'firstday_category',
      'event_label': 'firstday_label'
    });
    window.fbq('track', 'InitiateCheckout');
  }


}